package ru.urfc.portal.ui.client.descriptor;

import java.util.ArrayList;
import java.util.List;

import ru.urfc.portal.ui.client.renderers.CompositeRenderer;

import com.extjs.gxt.ui.client.data.ModelData;
import com.google.gwt.dom.client.Element;

public class CompositeGridField extends GridField {

	private List<GridField> gridFields = new ArrayList<GridField>();
	
	public CompositeGridField(GridField ... gridFields) {
		for (GridField gridField: gridFields) {
			this.gridFields.add(gridField);	
		}
	}
	
	public CompositeGridField addField(GridField gridField) {
		gridFields.add(gridField);
		return this;
	}
	
	public List<GridField> getGridFields() {
		return gridFields;
	}
	
	@Override
	protected Object _getValue(ModelData modelData) {
		return null;
	}

	public CompositeGridField assign() {
		return assign(null, " ");
	}

	public CompositeGridField assign(Element element) {
		return assign(element, " ");
	}
	
	public CompositeGridField assign(Element element, String separator) {
		return assign(element, "", separator, "");
	}

	public CompositeGridField assign(Element element, String starting, String separator, String ending) {
		CompositeRenderer renderer = new CompositeRenderer(this, element);
		renderer.init(starting, separator, ending);
		return (CompositeGridField) gridDescriptor.assign(renderer);
	}

	public void assignColumn(String separator, String columnTitle, int columnWidth) {
		assign(null, separator);
		gridDescriptor.addFieldColumn(this, columnTitle, columnWidth);
	}

	@Override
	public void accept(Visitor visitor) {
		visitor.visit(this);
	}
	
}
